<?php
session_cache_expire(999999999);
if (!isset($_SESSION)) {
    session_start();
}
//FC2BAA1A20B4D5190B122B383D7449FD

include 'invoicetax.php';
$soluonggiaodich = 0;
$tonggiacungcap = 0;
$tongthue = 0;
$tongtien = 0;
$tongcong = 0;
$tongtieninput = 0;
$_SESSION['invoice_arr'] = array();
$_SESSION['input_invoice'] = array();
unset($_SESSION['months']);
unset($_SESSION['years']);
$ob = new invoicetax();
$ob->newinvoicetax();
if (!isset($_REQUEST['months'])) {
    if (!isset($_SESSION['months']))
        $_SESSION['months'] = date("m");

    $ob->orday = date("d");
    $ob->ormonth = $_SESSION['months'];

    if (!isset($_REQUEST['years'])) {
        if (!isset($_SESSION['years']))
            $_SESSION['years'] = date("Y");
        $ob->oryear = $_SESSION['years'];
    }else {
        $_SESSION['years'] = $_REQUEST['years'];
        $ob->oryear = $_REQUEST['years'];
    }
} else {
    $ob->ormonth = $_REQUEST['months'];
    $_SESSION['months'] = $_REQUEST['months'];

    if (!isset($_REQUEST['years'])) {
        if (!isset($_SESSION['years']))
            $_SESSION['years'] = date("Y");
        $ob->oryear = $_SESSION['years'];
    }else {
        $_SESSION['years'] = $_REQUEST['years'];
        $ob->oryear = $_REQUEST['years'];
    }

    if ($_SESSION['months'] == date('m') && $_SESSION['years'] == date('Y')) {
        $ob->orday = date('d');
    } else {
        $ob->orday = 1;
    }
}

//echo $_SESSION['months'].'-'.$_SESSION['years'];

$songay = date("t", mktime(0, 0, 0, $ob->ormonth, 1, $ob->oryear));


$_SESSION['input_invoice'][] = $ob;

$typesearch=2;
if(isset($_REQUEST['typesearch']))
$typesearch=$_REQUEST['typesearch'];
if ($typesearch == 0) {
    $l_thoigiangiaodich = $l_thoigiangiaodich0;
}
if ($typesearch == 1) {
    $l_thoigiangiaodich = $l_thoigiangiaodich1;
}

if ($typesearch == 2) {
    $l_thoigiangiaodich = $l_thoigiangiaodich0.'/'.$l_thoigiangiaodich1;
}
$cusname1="";
if(isset($_REQUEST['cusname']))
$cusname1=$_REQUEST['cusname'];

$sql="SELECT or_order_tax.* 
from or_order_tax 
where month(or_order_tax.order_time_payment)='" . $_SESSION['months'] . "' 
		and year(or_order_tax.order_time_payment)='" . $_SESSION['years'] . "' "; 
if($typesearch!=2)
$sql.=" and or_order_tax.is_status='" . $typesearch . "' ";
$sql.=" and or_order_tax.order_cusname LIKE '%".$cusname1."%'
ORDER BY or_order_tax.is_status,or_order_tax.order_cusname,or_order_tax.order_time_transaction,or_order_tax.order_content;";
$sqlinvoice = mysql_query($sql);
?>
<style>
    <!--
    * {padding:0; margin:0;}
    -->
</style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.price_format.1.7.js"></script>
<script type="text/javascript" src="js/jquery.price_format.1.7.min.js"></script>
<link rel="stylesheet" type="text/css" href="admin/css/jsDatePick_ltr.min.css" />
<script type="text/javascript" src="admin/css/jsDatePick.min.1.3.js"></script>
<link	href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
<script language="javascript" src="js/cal2.js"></script>
<style type="text/css">
    .content_menu_expand{
        position:absolute; 
        right:-5px;
        top:20px;
        z-index:999;
        background-color: #ffffff;
        -moz-border-radius: 7px;
        -webkit-border-radius: 7px;
        color: #000000;
        width:300px; 
        max-height:180px;
        overflow:auto;
    }


    .passul{padding-left:0; border:1px solid black}
    .bgkhac {background: #eee;}
    .passul ul{padding:0px}
    .passul ul li {color:#474747; font-size:12px;padding: 5px 0;padding-left:5px;list-style: none;}
    .passul ul li:hover { background: #0A246A;color:white;text-decoration: none;list-style: none;}


</style>

<script type="text/javascript">
window.onload = function(){
    Load();
};
function Load(){
        $("#cusname").autocomplete("operations/rpc_search_invoice_tax.php", {
            selectFirst: true
		
        });
	
        $('#content_menu_expand').hide();
        $(document).click(function() {
                $("#content_menu_expand").hide();
        });
        $('#content_menu_expand').click(function(e) {
            e.stopPropagation();
        });
	
        $('#menu_expand').click(function(event) {
		
            var id=event.target.id;
            j=id.split("menu_expand");
		
            if ($('#content_menu_expand').is(":hidden")) {
            	var gt=document.getElementById("checkkhung").checked;
                if(gt==false){
                    $('#content_menu_expand').show();
                }
            }
            else {
                $('#content_menu_expand').hide();
            }
            return false;
        });   

}
function clickCustomer(gt){
    document.getElementById("cusname").value=gt;
    $('#content_menu_expand').hide();
}
    function delOneRow(id){
        var etax = document.getElementById("months");
        var txtthang = etax.options[etax.selectedIndex].value;
        var etax1 = document.getElementById("years");
        var txtnam = etax1.options[etax1.selectedIndex].value;

        var cusname = document.getElementById("cusname").value;
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp2=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp2.onreadystatechange=function(){
            if (xmlhttp2.readyState==4 && xmlhttp2.status==200){
                document.getElementById("showlist").innerHTML=xmlhttp2.responseText;
                var loi=document.getElementById("convoi").value;
                if(loi=="l_xoathanhcong"){
                    alert("<?php echo $l_xoathanhcong; ?>");
                }else{
                    alert(loi);
                }
                Load();
            }
        }
        xmlhttp2.open("POST","ajax/acc/or_save_invoice_tax1.php?id="+id+"&type=del&thang="+txtthang+"&nam="+txtnam+"&typesearch="+<?=$typesearch?>+"&cusname="+cusname,true);
        xmlhttp2.send();
    }
    function dokhung(){
        var gt=document.getElementById("checkkhung").checked;
        if(gt==true){
            document.getElementById("cusname").value="";
            document.getElementById("cusname").style.backgroundColor ="#e9edf4";
            $("#cusname").attr('readonly', 'readonly');
        }else{
            document.getElementById("cusname").value="";
            document.getElementById('cusname').style.backgroundColor ="#ffffff";
            $("#cusname").removeAttr('readonly');
            document.getElementById('cusname').focus();
        }
    }
</script>
<?php
$vyear = date("Y");
?>
<div  class="title" style="padding-top: 5px;font-weight: bold;"><?php echo $l_accountant; ?>&rarr; <?php if($status==0)echo $l_Invoice_thu;else echo $l_Invoice_chi; ?> &rarr; <?php echo $l_invoice_tax; ?></div>
<div class="content_code">

    <input type="hidden" name="content" value="ac_elisoft_order_tax_content" />
    <input type="hidden" name="songay" id="songay" value="<?= $songay ?>" />
    <div class="approval-right">		
        <form action="payment.php?content=ac_elisoft_order_tax_content" method="post" name="f_ac_elisoft_order_tax" id="f_ac_elisoft_order_tax">
            <table border="0" class="ftable" cellspacing="1" style="width: 840px">
                <tr>
                    <th style="height:30px;width:50px"><?php echo $l_month; ?></th>
                    <td style="height:30px;">
                        <select style="width:50px;height:24px;font-size:12px;text-align:center;valign:middle;" id="months" name="months">
                            <?php for ($i = 1; $i <= 12; $i++) { ?>
                                <option value="<?= $i ?>"  
                                <?php
                                if ($_SESSION['months'] == $i) {
                                    ?>
                                            selected="selected"
                                            <?php
                                        }
                                        ?>
                                        >
                                            <?php echo $i ?>
                                </option>
                            <?php } ?>
                        </select> 
                    </td>
                    <th style="height:30px;width:50px"><?php echo $l_year; ?></th>
                    <td style="height:30px;">
                        <select style="width:60px;height:24px;font-size:12px;text-align:center;valign:middle;" id="years" name="years">
                            <?php for ($i = 2012; $i <= ($vyear+7); $i++) { ?>
                                <option value="<?= $i ?>"  
                                <?php
                                if ($_SESSION['years'] == $i) {
                                    ?>
                                            selected="selected"
                                            <?php
                                        }
                                        ?>
                                        >
                                            <?php echo $i ?>
                                </option>
                            <?php } ?>
                        </select> 
                    </td>
                    <th style="width:90px"> <?=$l_company_name?></th>
                    <td>
                   
                    <div style="position:relative; ">
                                        <div style="float:left;">
                                            <input  type="text" size="30" id="cusname" name="cusname" value="<?=$cusname1?>" <?php if(isset($_REQUEST['checkkhung'])) echo 'readonly="readonly" style="background-color:#e9edf4;height: 24px; width:220px; border: 1px solid #c4c0c9;font-size: 12px;"'; else{?>  style="height: 24px; width:220px; border: 1px solid #c4c0c9;font-size: 12px;" <?php }?> autocomplete="off"; />
                                                    <div class="suggestionsBox" id="suggestions" style="display:none;">
                                                <img src="images/upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
                                                <div class="suggestionList" id="autoSuggestionsList">
                                                    &nbsp;
                                                </div>
                                            </div> 						
                                        </div>
                                        <div style=" float:left; position:relative; margin-top: 5px; margin-left: -21px ">
                                            <img alt="" src="images/arrow-down.png" id="menu_expand" >
                                            <div id="content_menu_expand" class="passul content_menu_expand" style="display:none;text-align: left;width: 220px;">
                                                <ul>
        <?php
        $sql = "select ac_customer.CustomerName from ac_customer where ac_customer.Activest=1 ORDER BY ac_customer.CustomerName ASC";
        $result = mysql_query($sql);
        if ($result) {
            $j = 0;
            while ($row = mysql_fetch_array($result)) {
                ?>
                                                            <li onmouseover="this.style.cursor='pointer'"  onmouseout="this.style.cursor='default'" onclick="clickCustomer('<?= $row['CustomerName'] ?>')" 
                                                            <?php
                                                            if ($j % 2 != 0) {
                                                                ?>
                                                                    class="bgkhac"
                                                                <?php
                                                            }
                                                            ?>
                                                                > <?php echo $row['CustomerName']; ?></li>
                                                                <?php
                                                                $j++;
                                                            }
                                                        }
                                                        ?>
                                                </ul>
                                            </div>
                                        </div>
                                    </div>
                                    <label><input type="checkbox" style="margin-top: 6px;" id="checkkhung"  name="checkkhung" <?php if(isset($_REQUEST['checkkhung'])) echo 'checked="checked"';?> onclick="dokhung();"/><?=$l_all?></label>
                    
                    </td>
                    <td>
                    	<label><input type="radio" id="typesearch" name="typesearch" value="0" <?php if($typesearch==0) echo 'checked="checked"';?>  /><?=$l_hdthu?></label>
                    	<label><input type="radio" id="typesearch" name="typesearch" value="1" <?php if($typesearch==1) echo 'checked="checked"';?> /><?=$l_hdchi?></label>
                    	<label><input type="radio" id="typesearch" name="typesearch" value="2" <?php if($typesearch==2) echo 'checked="checked"';?> /><?=$l_all?></label> 
                    </td>
                    <td>
                    	<input type="submit" value="<?=$l_search?>" class="btnupbg btnupload" style="width:50px;background: #4f81bd;"/>
                    </td>
                </tr>
            </table>
        </form>
        
<?php
$mang1=array();
$mang2=array();
 while ($r = mysql_fetch_array($sqlinvoice)) {
 	$ktdate = getdate(strtotime($r[order_time]));
 	if($r['is_status']==0)
 		$mang1[$r[order_cusname].'-'.$r['is_status']][]=array($r[orderid], $r[order_time],$ktdate[mon], $ktdate[mday], $ktdate[year], $r[order_cusname], $r[order_content], $r[order_quantity], $r[order_supply_rice], $r[order_tax], $r[order_total], $r[order_time_transaction], $r[order_time_payment], $r[is_status], $r[user_create], $r[date_create], $r['order_memo'], $r['status']);
 	else 
 		$mang2[$r[order_cusname].'-'.$r['is_status']][]=array($r[orderid], $r[order_time],$ktdate[mon], $ktdate[mday], $ktdate[year], $r[order_cusname], $r[order_content], $r[order_quantity], $r[order_supply_rice], $r[order_tax], $r[order_total], $r[order_time_transaction], $r[order_time_payment], $r[is_status], $r[user_create], $r[date_create], $r['order_memo'], $r['status']);
}
 	                    
                    ?>        
        <div style="clear:both"></div>
        <div style="position:relative" id="showlist">
             <table cellpadding="0" cellspacing="1" width="100%" border="0" class="ftable ">
                <tr >
                    <th style="width:10px"></th>
                    <th style="width:10px"><?= $l_no ?></th>
                    <th style="width:30px"><?= $l_month ?></th>
                    <th style="width:30px"><?= $l_days ?></th>
                    <th style="width:220px"><?= $l_customer ?></th>
                    <th style="width:30%"><?= $l_product_item ?></th>
                    <th style="width:60px"><?=$l_type_payment ?></th>
                    <th style="width:50px;display: none;"><?= $l_quantity ?></th>
                    <th style="width:90px"><?= $l_Supply_price ?></th>
                    <th style="width:90px"><?= $l_vat ?></th>
                    <th style="width:90px"><?= $l_amount ?></th>
                    <th style="width:90px"><?= $l_thoigiangiaodich ?></th> 
                    <th style="width:90px"><?= $l_payment ?></th> 
                    <th style="width:10%"><?= $l_memo ?></th>
                </tr>
                
                <?php 
                $vitri=0;
                $tonggiacungcap1 = 0;
                $tongthue1 = 0;
                $tongtien1 = 0;
                if(count($mang1)>0){
                foreach ($mang1 as $value =>$giatri){
                	$soluonggiaodich = 0;
                    $tonggiacungcap = 0;
                    $tongthue = 0;
                    $tongtien = 0;
                   	
                	
					for($i=0;$i<count($giatri);$i++){
					$vitri++;
                ?>
                	
                	 <tr style="padding:3px;">
                            <td>
                                <img onclick="delOneRow(<?=$giatri[$i][0]?>);" src="images/del.png" style="width:20px;height:20px;cursor:pointer;" title="<?php echo $l_delete; ?>" />
                            </td>
                            <td style="padding: 5px;cursor:pointer;" ><p style="width: 20px"><?= $vitri ?></p></td>
                            <td style="cursor:pointer;" ><p style="width: 20px"><?= $giatri[$i][2] ?></p></td>
                            <td style="cursor:pointer;" ><p style="width: 20px"><?= $giatri[$i][3] ?></p></td>
                            <td style="cursor:pointer;text-align:left;padding-left:3px;" ><p style="width: 200px"><?php echo $giatri[$i][5] ?></p></td>
                            <td style="cursor:pointer;text-align:left;padding-left:3px;" ><p style="min-width: 200px"><?= $giatri[$i][6] ?></p></td>
                            <td style="cursor:pointer;" ><p style="width: 60px"><?php if($giatri[$i][13]==0) echo $l_hdthu; else echo $l_hdchi;?></p></td>
                            <td style="display: none;cursor:pointer;" ><p style="width: 30px"><?= number_format($inobject->order_quantity) ?></p></td>
                            <td style="cursor:pointer;text-align:right;padding-right:3px;" ><p style="width: 90px"><?= number_format($giatri[$i][8]) ?></p></td>
                            <td style="cursor:pointer;text-align:right;padding-right:3px;" ><p style="width: 90px"><?= number_format($giatri[$i][9]) ?></p></td>
                            <td style="cursor:pointer;text-align:right;padding-right:3px;" ><p style="width: 90px"><?= number_format($giatri[$i][10]) ?></p></td>
                            <td style="cursor:pointer;" >
                                <p style="width: 80px"> <?php
							                if ($giatri[$i][11]== "0000-00-00")
							                    echo "";
							                else
							                    echo $giatri[$i][11];
                        					?>
                                </p>
                            </td>
                            
                            <td style="cursor:pointer;" >
                                <p style="width: 80px"> <?php
							                if ($giatri[$i][12]== "0000-00-00")
							                    echo "";
							                else
							                    echo $giatri[$i][12];
                        					?>
                                </p>
                            </td>
                            <td style="cursor:pointer;" ><p style="min-width: 120px"><?= $giatri[$i][16] ?></p></td>

		        <?php
		        	$soluonggiaodich++;
			        $tonggiacungcap +=$giatri[$i][8];
			        $tongthue +=$giatri[$i][9];
			        $tongtien +=$giatri[$i][10]; 
			        $tonggiacungcap1 +=$giatri[$i][8];
			        $tongthue1 +=$giatri[$i][9];
			        $tongtien1 +=$giatri[$i][10]; 
		        ?>
        	</tr>
               
		        <?php }?>
               
                <tr class="coltr2" style="height:30px;font-weight:bold;">
                    <td colspan="6"><!--<?php echo $l_all . '-' . $l_month; ?> : <font color="red"><?php echo $_SESSION['months'] ?></font>  -->  <?php echo $l_co; ?>  <font color="blue"><?php echo number_format($soluonggiaodich); ?></font> <?php echo $l_giaodich; ?></td>
                    <td></td>
                    <td style="display: none;"></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tonggiacungcap); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongthue); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongtien); ?></td>
                    <td colspan="3"></td>
                </tr>  
               <?php 
                }
                ?>
                <tr class="coltr2" style="height:30px;font-weight:bold;">
                    <td colspan="6"><?php echo $l_hdthu; ?></td>
                    <td></td>
                    <td style="display: none;"></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tonggiacungcap1); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongthue1); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongtien1); ?></td>
                    <td colspan="3"></td>
                </tr>
                <?php }
                $tonggiacungcap1 = 0;
                $tongthue1 = 0;
                $tongtien1 = 0;
                if(count($mang2)>0){
                foreach ($mang2 as $value =>$giatri){
                	$soluonggiaodich = 0;
                    $tonggiacungcap = 0;
                    $tongthue = 0;
                    $tongtien = 0;
                   	
                	
					for($i=0;$i<count($giatri);$i++){
					$vitri++;
                ?>
                	
                	 <tr style="padding:3px;">
                            <td>
                                <img onclick="delOneRow(<?=$giatri[$i][0]?>);" src="images/del.png" style="width:20px;height:20px;cursor:pointer;" title="<?php echo $l_delete; ?>" />
                            </td>
                            <td style="padding: 5px;cursor:pointer;" ><p style="width: 20px"><?= $vitri ?></p></td>
                            <td style="cursor:pointer;" ><p style="width: 20px"><?= $giatri[$i][2] ?></p></td>
                            <td style="cursor:pointer;" ><p style="width: 20px"><?= $giatri[$i][3] ?></p></td>
                            <td style="cursor:pointer;text-align:left;padding-left:3px;" ><p style="width: 200px"><?php echo $giatri[$i][5] ?></p></td>
                            <td style="cursor:pointer;text-align:left;padding-left:3px;" ><p style="min-width: 200px"><?= $giatri[$i][6] ?></p></td>
                            <td style="cursor:pointer;" ><p style="width: 60px"><?php if($giatri[$i][13]==0) echo $l_hdthu; else echo $l_hdchi;?></p></td>
                            <td style="display: none;cursor:pointer;" ><p style="width: 30px"><?= number_format($inobject->order_quantity) ?></p></td>
                            <td style="cursor:pointer;text-align:right;padding-right:3px;" ><p style="width: 90px"><?= number_format($giatri[$i][8]) ?></p></td>
                            <td style="cursor:pointer;text-align:right;padding-right:3px;" ><p style="width: 90px"><?= number_format($giatri[$i][9]) ?></p></td>
                            <td style="cursor:pointer;text-align:right;padding-right:3px;" ><p style="width: 90px"><?= number_format($giatri[$i][10]) ?></p></td>
                            <td style="cursor:pointer;" >
                                <p style="width: 80px"> <?php
							                if ($giatri[$i][11]== "0000-00-00")
							                    echo "";
							                else
							                    echo $giatri[$i][11];
                        					?>
                                </p>
                            </td>
                            
                            <td style="cursor:pointer;" >
                                <p style="width: 80px"> <?php
							                if ($giatri[$i][12]== "0000-00-00")
							                    echo "";
							                else
							                    echo $giatri[$i][12];
                        					?>
                                </p>
                            </td>
                            <td style="cursor:pointer;" ><p style="min-width: 120px"><?= $giatri[$i][16] ?></p></td>

		        <?php
		        	$soluonggiaodich++;
			        $tonggiacungcap +=$giatri[$i][8];
			        $tongthue +=$giatri[$i][9];
			        $tongtien +=$giatri[$i][10]; 
			        $tonggiacungcap1 +=$giatri[$i][8];
			        $tongthue1 +=$giatri[$i][9];
			        $tongtien1 +=$giatri[$i][10]; 
		        ?>
        	</tr>
               
		        <?php }?>
               
                <tr class="coltr2" style="height:30px;font-weight:bold;">
                    <td colspan="6"><!--<?php echo $l_all . '-' . $l_month; ?> : <font color="red"><?php echo $_SESSION['months'] ?></font>  -->  <?php echo $l_co; ?>  <font color="blue"><?php echo number_format($soluonggiaodich); ?></font> <?php echo $l_giaodich; ?></td>
                    <td></td>
                    <td style="display: none;"></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tonggiacungcap); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongthue); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongtien); ?></td>
                    <td colspan="3"></td>
                </tr>  
               <?php 
                }
                ?>
                <tr class="coltr2" style="height:30px;font-weight:bold;">
                    <td colspan="6"><?php echo $l_hdchi; ?></td>
                    <td></td>
                    <td style="display: none;"></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tonggiacungcap1); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongthue1); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongtien1); ?></td>
                    <td colspan="3"></td>
                </tr>
                <?php }?>
          </table>
      
        </div> 
      
    </div>
</div>